<?php

class Barcode extends BZ_Controller
{
    function _init()
    {
        $this->load->library(array('virefyorderedit', 'aes'));
        $this->load->model('order_base_model', 'order_base');
        $this->load->model('scenery_base_model', 'scenery_base');
    }

    public function show($payId)
    {
        $result = $this->order_base->findByPayId($payId);
        if ($result->num_rows() == 0) {
            $this->alertJumpPre('交易编码不存在');
        }
        $result = $result->result();
        if ($result[0]->calculate_method != 3) {
            show_404();
        }
        if (((int)$result[0]->bit_pay & 65536) != 65536) {
            $this->alertJumpPre('订单未支付');
        }
        $scenic = $this->scenery_base->findBySid($result[0]->sid);
        if (!is_file($this->config->upload_image_path('common/ewm/', 'scenic-payid-'.$payId.'.png'))){
            $data = array(
                'url'                  => $this->qrcodeEncrypt(array('pay_id' => $payId, 'sid' => $scenic->row()->sid)), //二维码内容
                'errorCorrectionLevel' => 'L', //容错级别
                'matrixPointSize'      => 12, //生成图片大小
                'QR'                   => $this->config->upload_image_path('common/ewm/','qrcode.png'),
                'logo'                 => '', //准备好的logo图片
                'output'               => $this->config->upload_image_path('common/ewm/', 'scenic-payid-'.$payId.'.png')
            );
            $this->load->library('qrcode/qr_code', null, 'qr_code');
            $this->qr_code->generate($data);
        }
        $data['orderList'] = $result;
        $data['scenic'] = $scenic->row();
        return $this->load->view('scenic/barcode/show', $data);
    }

     /**
     * 二维码加个密
     */
    private function qrcodeEncrypt($qrcode)
    {
        return $this->aes->aes128cbcEncrypt(json_encode($qrcode));
    }
}